#include "Utility.h"



// WARNING!! if iBitMap == 0 the result is undefined
size_t FindLeastSignificantBitSetIndex(const size_t iBitMap)
{
	#ifdef _MSC_VER
		unsigned long index;
		_BitScanForward(&index, iBitMap);
		//return 0x1f - __lzcnt(iBitMap); // Not supported on all platform
		return index;
	#else
		#error "Not defined for the current platform"
	#endif
}



// WARNING!! if iBitMap == 0 the result is undefined
size_t FindMostSignificantBitSetIndex(const size_t iBitMap)
{
	#ifdef _MSC_VER
		unsigned long index;
		_BitScanReverse(&index, iBitMap);
		return index;
	#else
		#error "Not defined for the current platform"
	#endif
}



size_t FindLeastSignificantBitSetMask(const size_t iBitMap)
{
	#ifdef _MSC_VER
		#pragma warning(disable : 4146)
			return (iBitMap & -iBitMap);
		#pragma warning(default : 4146)
	#else
		#error "Not defined for the current platform"
	#endif
}
